<%@ page contentType="text/html;charset=utf-8"%>

<%@ page import="com.lovefreedom.psi.bean.*"%>
<%@ page import="java.util.List" %>
<%@ page import="com.lovefreedom.psi.dao.*" %>
<%@ page import="com.lovefreedom.psi.dao.impl.*" %>

<%
	List list = (List)request.getAttribute("goodsList");
	System.out.println("goodsListSize="+list.size());
%>

<html>
<head>
<title>货品管理</title>
<link type="text/css" rel="stylesheet" href="../../scripts/ui/skins/Aqua/css/ligerui-all.css" />
<link type="text/css" rel="stylesheet" href="../images/style.css" />
<link type="text/css" rel="stylesheet" href="../../css/pagination.css" />
<script type="text/javascript" src="../../scripts/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../../scripts/ui/js/ligerBuild.min.js"></script>
<script type="text/javascript" src="../js/function.js"></script>

<script language="javascript">

//获取选中数量
function getCheckedCount()
{  
  	var count = 0;
  	for (var i=0; i < document.goodsform.length; i++)
  	{
    		if(document.goodsform.elements[i].checked) count++;
    	}
  	return count;
}
//进入编辑页面
function edit()
{
	var count = getCheckedCount();	
	if(count == 0)
	{
		//没有选中
		alert("请选中要修改的货品!");
		return;
	}
	else if(count > 1)
	{
		//选中了多个
		alert("最多只能选择一项");
		return;
	}
	else
	{		
    	//提交表单
		document.goodsform.action="update.jsp";
		document.goodsform.submit();  			
	}
	return;
}

//删除
function del()
{
 	if (getCheckedCount() == 0) 
 	{
    	alert("请选中要删除的货品!");
    	return;
  	}
  	if (confirm("已使用的货品不能被删除，您确认要删除这些货品吗?")) 
  	{
    	//提交表单
		document.goodsform.action="delete.action";
		document.goodsform.submit();       		
  	}
}

//修改分页大小
function changePageSize()
{
  	if (document.goodsform.txtPageNum.value > 0) 
  	{
    	//将新的值填入cookies。
    	var cookie1 = "pageSize=" + document.goodsform.txtPageNum.value;   	
    	document.cookie=cookie1;    	
    	//提交表单
		document.goodsform.action="list.action?page=1";
		document.goodsform.submit();       		
  	}
}
//进入查询结果页面
function search()
{
    //提交表单
	document.goodsform.action="list.action?page=1";
	document.goodsform.submit();       		
}

</script>

</head>
<body class="mainbody">
<form method="post" name="goodsform">
    <div class="navigation">首页 &gt; 货品管理 &gt; 货品列表</div>
    <div class="tools_box">
	<div class="tools_bar">
	    <div class="search_box">
			<input type="text" ID="txtKeywords" name="txtKeywords"  CssClass="txtInput">
            <input type="submit"  ID="btnSearch" value="搜 索" CssClass="btnSearch" onclick="search()" >
		</div>
	    <a href="add.jsp" class="tools_btn"><span><b class="add">添加货品</b></span></a>
	    <a href="#" class="tools_btn" onclick="edit()"><span><b class="edit">修改货品</b></span></a>
	    <a href="#" class="tools_btn" onclick="del()"><span><b class="delete">删除货品</b></span></a>
	    <a href="import.jsp" class="tools_btn" onclick="del()"><span><b class="import">导入货品</b></span></a>
	    <a href="#" class="tools_btn" onclick="del()"><span><b class="export">导出货品</b></span></a>
        </div>
    </div>

    <!--列表展示.开始-->

    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
      <tr>
        <th width="10%">选择</th>
        <th width="20%">分类</th>
        <th width="10%">编号</th>        
        <th width="20%">名称</th>
		<th width="10%">单位</th>
		<th width="10%">期初数量</th>		
		<th width="10%">参考进价</th>	
		<th width="10%">参考售价</th>	
      </tr>
<%
	Goods goods = new Goods();
	for(int i = 0; i < list.size(); i++)
	{	
		goods = (Goods)list.get(i);  	
%>
      <tr>
        <td align="center"><input type="checkbox" name="goodsIds" value=<%=goods.getId()%>></td>
        <td align="center"><%=goods.getCategory().getName()%></td>
        <td align="center"><%=goods.getCode()%></td>
        <td align="center"><%=goods.getName()%></td>
        <td align="center"><%=goods.getUnit()%></td>
        <td align="center"><%=goods.getBeginInventory()%></td>
        <td align="center"><%=goods.getPurchasePrice()%></td>
        <td align="center"><%=goods.getSellingPrice()%></td>
      </tr>
<%
	}	
%>     
	<%=list.size()==0 ? "<tr><td align=\"center\" colspan=\"9\">暂无记录</td></tr>" : ""%>
	</table>
    <!--列表展示.结束-->
    
    <!--分页处理-->
    <div class="line15"></div>
    <div class="page_box">
      <div id="PageContent" class="flickr right">${requestScope.pageContent}</div>   
      <div class="left">
         显示<input type="text" name="txtPageNum" onChange="changePageSize()" value="${requestScope.pageSize}">条/页
      </div>   
    </div>
    <div class="line10"></div>    
</form>
</body>
</html>


